package com.ruoyi.web.controller.drug;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.drug.domain.DrugPhysic;
import com.ruoyi.drug.service.IDrugPhysicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/drug/physic")
public class DrugPhysicController extends BaseController {
    @Autowired
    private IDrugPhysicService drugPhysicService;

    /**
     * 获取药品列表
     */
    @PreAuthorize("@ss.hasPermi('drug:physic:list')")
    @GetMapping("/list")
    public TableDataInfo list(DrugPhysic drugPhysic)
    {
        startPage();
        List<DrugPhysic> list = drugPhysicService.selectPhysicList(drugPhysic);
        System.out.println(list);
        return getDataTable(list);
    }

    /**
     * 根据药品编号获取药品信息
     */
    @PreAuthorize("@ss.hasPermi('drug:physic:query')")
    @GetMapping(value = "/{physicId}")
    public AjaxResult getInfo(@PathVariable Long physicId)
    {
        return success(drugPhysicService.selectPhysicById(physicId));
    }

    /**
     * 修改药品信息
     */
    @PreAuthorize("@ss.hasPermi('drug:physic:edit')")
    @Log(title = "药品信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody DrugPhysic drugPhysic)
    {
        drugPhysic.setUpdateBy(getUsername());
        return toAjax(drugPhysicService.updatePhysic(drugPhysic));
    }
    /**
     * 删除药品
     */

    @PreAuthorize("@ss.hasPermi('drug:physic:remove')")
    @Log(title = "药品信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{physicIds}")
    public AjaxResult remove(@PathVariable Long[] physicIds){
        return toAjax(drugPhysicService.deletePhysicByIds(physicIds));
    }
}
